package org.btik.light.mobile.common.handler.adaptor;

import android.view.View;
import org.btik.light.mobile.common.handler.DevBinder;
import org.btik.light.mobile.meta.mo.DefaultDevMo;

import java.util.function.Consumer;

/**
 * @author lustre
 * @since 2023/5/3 10:32
 */
public class ClickerAdaptor implements DevBinder, View.OnClickListener {

    private final Consumer<View> viewConsumer;

    public ClickerAdaptor(Consumer<View> viewConsumer) {
        this.viewConsumer = viewConsumer;
    }

    @Override
    public void bind(DefaultDevMo devMo) {
        if (viewConsumer instanceof DevBinder) {
            ((DevBinder) viewConsumer).bind(devMo);
        }
    }

    @Override
    public void onClick(View v) {
        viewConsumer.accept(v);
    }
}
